package com.example.mytayunapi.Controller;

import com.example.mytayunapi.Entity.adviceInfo;
import com.example.mytayunapi.Entity.productsInfo;
import com.example.mytayunapi.Service.adviceInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("advise")
public class adviceController {

    //分页
    //http://localhost:8080/advise/page
    @GetMapping("/page")
    public PageInfo<adviceInfo> pageInfo(@RequestParam Integer page, @RequestParam Integer size){
        return adviceinfoService.getPageInfo(page,size);
    }

    @Autowired
    private adviceInfoService adviceinfoService;

    @GetMapping("/queryall")
    public List<adviceInfo> queryadvise() {
        return adviceinfoService.selectAllAdviceInfo();
    }

    @GetMapping("/queryadvise")
    public List<adviceInfo> queryall(Integer Advice_id) {
        List<adviceInfo> adviceInfos = null;
        if (Advice_id == null) {
            adviceInfos = adviceinfoService.selectAllAdviceInfo();
        }else {
            adviceInfos = adviceinfoService.selectAllAdviceInfoByAdviceId(Advice_id);
        }
        return adviceInfos;
    }

    @PostMapping("/insert")
    public Integer insertadvice(@RequestBody adviceInfo adviceinfo) {
        return adviceinfoService.insertAdviceInfo(adviceinfo);
    }

    @GetMapping("del/{id}")
    private Integer delAdviceInfoById(@PathVariable Integer id) {
        return adviceinfoService.deleteAdviceByID(id);
    }

}
